JavaScript日期加减 |
您所在的位置:网站首页 › js 日期加减 › JavaScript日期加减 |
JS中的日期加减使用以下方式: varcurrentDate = new Date(); 对日期加减: date.setDate(date.getDate()+n); 对月加减: date.setMonth(date.getMonth()+n); 对年加减: date.setFullYear(date.getFullYear()+n); 对小时、周等,都可以使用类似的方式修改。 同时如果对日加减的时候跨越了月、年,那么JS的date类型会自动的处理跨越问题,不需要我们处理。需要注意的是返回的月份是从0开始计算的,也就是说返回的月份要比实际月份少一个月,因此要相应的加上1
参考: https://blog.csdn.net/li_xiao_dai/article/details/20123173 https://blog.csdn.net/hekewangzi/article/details/51003063 https://blog.csdn.net/xueyepiaoling/article/details/6306366
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |